﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SadlandVillage.Core;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Media;

namespace SadlandVillage.Minigames.Club
{
    public class ClubGameCinematic : GameScene
    {
        private Texture2D Background;
        private MessageBox TextBox;
        private Song Bgm;

        public event ExitSceneEventHandler CinematicOver;


        public ClubGameCinematic(ContentManager content, SpriteBatch spriteBatch)
            : base(content, spriteBatch)
        {
            TextBox = new MessageBox(content, spriteBatch)
            {
                Text = Constants.GoomaIntro,
                Position = GetTextBoxPosition(),
                Lines = 3,
                Columns = 50,
                BackColor = Color.Green,
                ForeColor = Color.White,
                DrawShadow = false,
                SpeakerName = "Gooma"
            };

        }

        public override void LoadContent()
        {
            Background = content.Load<Texture2D>(@"Minigames\Club\cinematic-bg");

            TextBox.LoadContent();
            TextBox.Blur += new EventHandler(TextBox_Blur);

            Bgm = content.Load<Song>(@"Minigames\Club\bgm");
        }

        void TextBox_Blur(object sender, EventArgs e)
        {            
            if (CinematicOver != null)
            {
                CinematicOver();
            }
        }

        private Vector2 GetTextBoxPosition()
        {
            return new Vector2(10f, 400f);
        }

        public override void Update(GameTime gameTime)
        {
            if (MediaPlayer.State != MediaState.Playing)
            {
                MediaPlayer.Play(Bgm);
            }
            TextBox.Update(gameTime);
        }

        public override void Draw(GameTime gameTime)
        {
            spriteBatch.Begin();
            spriteBatch.Draw(Background, Vector2.Zero, Color.White);
            spriteBatch.End();
            TextBox.Draw(gameTime);
        }
    }
}
